//
//  HOTBaseViewController.m
//  Genpara
//
//  Created by AndyChang.zhang on 14-8-27.
//  Copyright (c) 2014年 zhangchh. All rights reserved.
//

#import "HOTBaseViewController.h"
#import "HOTCommBtn.h"
#import "ZZZPopupView.h"
#import "ZZZPopupManager.h"
#import "MBProgressHUD.h"
#import "MBProgressHUDManager.h"
#import "HOTCommChatBar.h"
#import "HOTStoreViewController.h"
#import "HOTNaviBar.h"
#import "HOTOrderPreviewViewController.h"
#import "HOTMessageChatViewController.h"

typedef void (^action)(void);
@interface HOTBaseViewController ()  <ZZZPopupViewDelegate> {
    
    RMStore *_storeHandler;
    BOOL isAppeared;
    
}

@property(nonatomic,strong)NSDictionary *titleAttributeDic;

@end


@implementation HOTBaseViewController

@synthesize httpClient = _httpClient;
@synthesize hudManager = _hudManager;
@synthesize userInfo = _userInfo;
@synthesize isShowHud = _isShowHud;
@synthesize storeHandler = _storeHandler;

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    isAppeared = YES;

    _httpClient = [HOTHttpClient client];
    
    //隐藏系统的返回按钮
    
    //self.view.backgroundColor = [UIColor blackColor];
    [self.navigationItem setHidesBackButton:YES];
    self.navigationController.navigationBar.translucent = NO;
    
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftBtn setImage:[UIImage imageNamed:@"btn_back"] forState:UIControlStateNormal];
    [leftBtn setImage:[UIImage imageNamed:@"btn_back_on"] forState:UIControlStateHighlighted];
    leftBtn.frame = CGRectMake(0, 0, 40, 40);
    [leftBtn setImageEdgeInsets:UIEdgeInsetsMake(0, -20, 0, 0)];
    [leftBtn addTarget:self action:@selector(backBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftBarBtnItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    [self.navigationItem setLeftBarButtonItem:leftBarBtnItem animated:YES];
    
    

    //[self.navigationController.navigationBar setTitleTextAttributes:@{
                                                                      //NSForegroundColorAttributeName:[UIColor whiteColor],
                                                                      //NSFontAttributeName:[UIFont boldSystemFontOfSize:18]}];
    _hudManager = [[MBProgressHUDManager alloc] initWithView:self.view];
    
    _userInfo = [HOTUserInfo defaultUser];

}

//用新的view初始化hud的方法
-(void)initHudWithView:(UIView *)view {
    
    _hudManager = [[MBProgressHUDManager alloc] initWithView:view];
}

-(void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    isAppeared = YES;
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillChanged:) name:UIKeyboardWillChangeFrameNotification object:nil];
    
    if (self.titleAttributeDic) {
        
        [self.navigationController.navigationBar setTitleTextAttributes:self.titleAttributeDic];
    }
    
}

-(void)viewWillDisappear:(BOOL)animated {
    
    isAppeared = NO;
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
}

-(void)setNaviTitle:(NSString *)title {
    
    [self setNaviTitle:title fontSize:24 fontName:HOTTitleFont_ROUNDED_X];
}

-(void)addRightBtnTarget:(id)target
                action:(SEL)selector
                   image:(UIImage *)btnImage
                  hImage:(UIImage *)hImage {
    

    self.navigationItem.rightBarButtonItem = [self createBarButtomItemTarget:target action:selector image:btnImage hImage:hImage edgeInsets:UIEdgeInsetsMake(0, 0, 0, -20)];
}

-(UIBarButtonItem *)createBarButtomItemTarget:(id)target
                                       action:(SEL)selector
                                        image:(UIImage *)btnImage
                                       hImage:(UIImage *)hImage
                                   edgeInsets:(UIEdgeInsets)edgeInsets {
    
    HOTCommBtn *btn = [HOTCommBtn buttonWithType:UIButtonTypeCustom];
    [btn setImage:btnImage
                   forState:UIControlStateNormal];
    if (hImage) {
        [btn setImage:hImage
                       forState:UIControlStateHighlighted];
    }
    
    btn.frame = CGRectMake(0, 0, btnImage.size.width, btnImage.size.height);
    [btn setImageEdgeInsets:edgeInsets];
    [btn addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    
    
    UIBarButtonItem *btnItem = [[UIBarButtonItem alloc] initWithCustomView:btn];

    return btnItem;
}

/**
 *  设置导航栏上的title
 *
 *  @param title          title description
 *  @param fontSize       fontSize description
 *  @param titleFontStyle titleFontStyle description
 */
-(void)setNaviTitle:(NSString *)title
       fontSize:(float)fontSize
       fontName:(HOTTitleFontSytle)titleFontStyle {
    
    NSString *fontName = kHOT_FONT_HELVETICA_NEUE;
    switch (titleFontStyle) {
        case HOTTitleFont_DEFAULT:

            break;
        case HOTTitleFont_ROUNDED_X:
            
            fontName = kHOT_FONT_ROUNDED_X;
            
            break;
        case HOTTitleFont_HIRAGINO_KAKU_W3:
            
            fontName = kHOT_FONT_HIRAGINO_KAKU_W3;
            
            break;
        case HOTTitleFont_HIRAGINO_KAKU_W6:
            
            fontName = kHOT_FONT_HIRAGINO_KAKU_W6;
            
            break;
        case HOTTitleFont_HELVETICA_NEUE:
            
            fontName = kHOT_FONT_HELVETICA_NEUE;
            
            break;
            
        default:
            break;
    }
    
    self.titleAttributeDic = @{
                               NSForegroundColorAttributeName:[UIColor whiteColor],
                               NSFontAttributeName:[UIFont fontWithName:fontName size:fontSize]};
    [self.navigationController.navigationBar setTitleTextAttributes:self.titleAttributeDic];
    
    [super setTitle:title];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(BOOL)prefersStatusBarHidden {
    
    return YES;
}

-(void)setNavBarHidden:(BOOL)flg {
    
    [self.navigationController setNavigationBarHidden:flg animated:YES];
}

-(void)backBtnClicked:(id)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)createRightBtnWithType:(HOTNaviBarRightBtnType)rightBtnType {
    
    
    NSString *btnImageName = nil;
    if (rightBtnType == HOTNaviBarRightBtnDone) {
        //决定按钮
        btnImageName = @"btn_decision";
        
        [self addRightBtnTarget:self action:@selector(rightBtnClicked:) image:[UIImage imageNamed:@"btn_decision_off"] hImage:[UIImage imageNamed:@"btn_decision_on"]];
        
    } else if (rightBtnType == HOTNaviBarRightBtnEdit) {
        
        btnImageName = @"btn_edit";
        
        [self addRightBtnTarget:self action:@selector(rightBtnClicked:) image:[UIImage imageNamed:@"btn_edit_off"] hImage:[UIImage imageNamed:@"btn_edit_on"]];
    }
    
}

-(void)rightBtnClicked:(HOTCommBtn *)sender {
    
    //HOTNaviBarRightBtnType style = [[sender.userInfo objectForKey:@"btnType"] intValue];
    
    
}

-(void)requestWithURL:(NSString *)urlString
           Parameters:(id)parameters
              success:(void (^)(NSInteger result, id data))success
              failure:(void (^)(NSError *error, NSString *errMsg))failure {
    
    
    [self.httpClient requestWithURL:urlString Parameters:parameters success:^(id responseObject) {
        
        if (!isAppeared) {
            return ;
        }
        
        NSLog(@"====服务器返回数据：%@", responseObject);
        NSString *result = [responseObject objectForKey:REQ_KEY_RESULT];
        NSString *errMsg = [responseObject objectForKey:REQ_KEY_MSG];
        if (![result isEqualToString:@"1"]) {
            //接口调用成功，但result不等于1的场合

            if (_isShowHud) {
                [self loadingSuccess];
                _isShowHud = NO;
            }
            
            
            
            failure(nil, errMsg);
            
            
        } else {
            
            
            id data = [responseObject objectForKey:REQ_KEY_DATA];
            success([result integerValue], data);
        }
        
    } failure:^(NSError *error) {
        if (!isAppeared) {
            return ;
        }
        failure(error, nil);
//        [self.hudManager hide];
//        ZZZPopupView *popupView = [[ZZZPopupView alloc] initWithTitle:ALERT_TITLE message:errMsg delegate:nil cancelButtonTitle:nil otherButtonTitle:ALERT_BTN_OK];
//        
//        [popupView showInWindow];
    }];
}

-(void)requestGetWithURL:(NSString *)urlString
           Parameters:(id)parameters
              success:(void (^)(id data))success
                 failure:(void (^)(NSError *error, NSString *errMsg))failure {
    
    [self.httpClient requestGETWithURL:urlString Parameters:parameters success:^(id responseObject) {
        if (!isAppeared) {
            return ;
        }
        NSLog(@"====服务器返回数据：%@", responseObject);

        success(responseObject);
        
    } failure:^(NSError *error) {
        if (!isAppeared) {
            return ;
        }
        failure(error, nil);
//        [self.hudManager hide];
//        ZZZPopupView *popupView = [[ZZZPopupView alloc] initWithTitle:ALERT_TITLE message:errMsg delegate:nil cancelButtonTitle:nil otherButtonTitle:ALERT_BTN_OK];
//        
//        [popupView showInWindow];
    }];
}

-(void)uploadImageWithPost:(NSString *)urlString
                 imageData:(NSData *)imageData
                uploadName:(NSString *)uploadName
              Parameters:(id)parameters
                 success:(void (^)(id data))success
                 failure:(void (^)(NSError *error, NSString *errMsg))failure {
    
    [self.httpClient uploadDataWithURL:urlString
                            uploadData:imageData
                            uploadName:@"file_path"
                              fileName:@"image.jpg"
                            Parameters:parameters
                              mimeType:@"image/jpeg"
                               success:^(id responseObject) {

                                   if (!isAppeared) {
                                       return ;
                                   }
        NSLog(@"====服务器返回数据：%@", responseObject);
        
       NSString *result = [responseObject objectForKey:REQ_KEY_RESULT];
       NSString *errMsg = [responseObject objectForKey:REQ_KEY_MSG];
       if (![result isEqualToString:@"1"]) {
           //接口调用成功，但result不等于1的场合
           if (failure == nil) {
               
               if (_isShowHud) {
                   [self.hudManager hide];
                   _isShowHud = NO;
               }
               
               ZZZPopupView *popupView = [[ZZZPopupView alloc] initWithTitle:ALERT_TITLE
                                                                     message:errMsg
                                                                    delegate:nil
                                                           cancelButtonTitle:nil
                                                            otherButtonTitle:ALERT_BTN_OK];
               
               [popupView showInWindow];
           } else {
               if (_isShowHud) {
                   [self loadingSuccess];
                   _isShowHud = NO;
               }
               failure(nil,errMsg);
           }
           
       } else {
           //接口调用成功
           id data = [responseObject objectForKey:REQ_KEY_DATA];
           success(data);
       }
        
        //success(responseObject);
        
    } failure:^(NSError *error) {
        
        if (!isAppeared) {
            return ;
        }
        failure(error, nil);
//        [self.hudManager hide];
//        ZZZPopupView *popupView = [[ZZZPopupView alloc] initWithTitle:ALERT_TITLE message:errMsg delegate:nil cancelButtonTitle:nil otherButtonTitle:ALERT_BTN_OK];
//        
//        [popupView showInWindow];
    }];
}

-(NSString *)getErrMsgWith:(NSString *)itemName
                  itemType:(HOTInputItemType)itemType {
    
    if (itemType == HOTInputItemText) {
        
        return [NSString stringWithFormat:@"%@を入力してください。", itemName];
    } else if (itemType == HOTInputItemPullDown) {
        
        return [NSString stringWithFormat:@"%@を選択してください。", itemName];
    }
    
    return itemName;
}

-(void)showLoading {
    _isShowHud = YES;
    [self.hudManager showIndeterminateWithMessage:MSG_GAMEN_LOADING];
}

-(void)loadingSuccess {
    
    [self.hudManager hideWithAfterDuration:0.3 completion:^(void) {
        
        _isShowHud = NO;
    }];
}

-(void)showLoadingWithMessage:(NSString *)msg {
    
    _isShowHud = YES;
    [self.hudManager showIndeterminateWithMessage:msg];
}

-(void)showSuccessWithMessage:(NSString *)msg complection:(void (^)())completion{
    
    [self.hudManager showSuccessWithMessage:msg duration:1.5 complection:completion];
}

-(void)showSuccessWithMessage:(NSString *)msg {
    
    
    [self.hudManager showSuccessWithMessage:msg duration:1.5];
}

#pragma mark - ZZZPopupViewDelegate
-(void)popupView:(ZZZPopupView *)popupView buttonKind:(ZZZPopupViewBtnKind)btnKind {
    
    
    
    if (popupView.tag == 99991 || popupView.tag == 99992) {
        
        action action = [popupView.userInfo objectForKey:@"action"];
        if (action) {
            
            action();
        }
    } else if (popupView.tag == 99993) {
        //余额不足的提示
        if (btnKind == ZZZPopupViewConfirmBtnKind) {
            
            //売店へ
            if (self.presentingViewController != nil) {
                
                //点击取消按钮时
                if (![self isKindOfClass:[HOTOrderPreviewViewController class]]
                    && ![self isKindOfClass:[HOTMessageChatViewController class]]) {
                    //当前不在发注书预览界面或聊天界面时，点击壳店不返回上级界面，直接进入壳店界面
                    [self dismissViewControllerAnimated:YES completion:nil];
                }
                
                
            } else {
                
                //点击取消按钮时
                if (![self isKindOfClass:[HOTOrderPreviewViewController class]]
                    && ![self isKindOfClass:[HOTMessageChatViewController class]]) {
                    //当前不在发注书预览界面或聊天界面时，点击壳店不返回上级界面，直接进入壳店界面
                    [self.navigationController popViewControllerAnimated:YES];
                }
            }
            
            HOTStoreViewController *svc = [[HOTStoreViewController alloc] initWithNibName:@"HOTStoreViewController" bundle:nil];
            
            [self.navigationController pushViewController:svc animated:YES];
        } else {
            
            //点击取消按钮时
            if ([self isKindOfClass:[HOTOrderPreviewViewController class]]
                || [self isKindOfClass:[HOTMessageChatViewController class]]) {
                //当前在发注书预览界面或聊天界面时，点击取消不返回上级界面
                return;
            }
            
            if (self.presentingViewController != nil) {
                
                [self dismissViewControllerAnimated:YES completion:nil];
            } else {
                
                [self.navigationController popViewControllerAnimated:YES];
            }
        }
    }
}

-(void)alertNoDataAgainMessage:(void (^)(void))action {
    
    ZZZPopupView *popupView = [[ZZZPopupView alloc] initWithTitle:ALERT_TITLE
                                                          message:MSG_NO_DATA_AGAIN
                                                         delegate:self
                                                cancelButtonTitle:nil
                                                 otherButtonTitle:ALERT_BTN_OK];
    popupView.tag = 99991;
    if (action) {
        popupView.userInfo = @{@"action":action};
    }
    
    [popupView showInWindow];
}

-(void)alertNoDataMessage:(void (^)(void))action{
    
//    ZZZPopupView *popupView = [[ZZZPopupView alloc] initWithTitle:ALERT_TITLE
//                                                          message:MSG_NO_DATA
//                                                         delegate:self
//                                                cancelButtonTitle:nil
//                                                 otherButtonTitle:ALERT_BTN_OK];
//    popupView.tag = 99992;
//    if (action) {
//        popupView.userInfo = @{@"action":action};
//    }
//    [popupView showInWindow];
}


-(void)showChatInputBar:(BOOL)showFlg {
    
    if (showFlg) {
        
        if (self.chatInputBar == nil) {
            
            NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"HOTCommChatBar" owner:self options:nil];
            self.chatInputBar = [nibs lastObject];
            
            //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillChanged:) name:UIKeyboardWillChangeFrameNotification object:nil];
        }

        //UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
        self.chatInputBar.topVc = self;
        self.chatInputBar.frame = CGRectMake(0, self.view.bounds.size.height - self.chatInputBar.bounds.size.height, self.chatInputBar.bounds.size.width, self.chatInputBar.bounds.size.height);
        
        [self.view addSubview:self.chatInputBar];
        
        //self.chatTextView.inputAccessoryView = self.chatTextView;
    }
}

-(void)showChatInputBar:(BOOL)showFlg withStyle:(HOTCharBarStyle)barStyle {
    
    if (showFlg) {
        
        if (self.chatInputBar == nil) {
            
            NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"HOTCommChatBar" owner:self options:nil];
            
            
            if (barStyle == HOTCharBarStyleForReplay) {
                
                //回复框 不带表情
                self.chatInputBar = [nibs lastObject];
                
            } else if (barStyle == HOTCharBarStyleForImageOnly || barStyle == HOTCharBarStyleForImageProject) {
                
                //不带发注书的
                self.chatInputBar = [nibs objectAtIndex:1];
            }
//            else if (barStyle == HOTCharBarStyleForImageProject) {
//                
//                //带发注书的
//                self.chatInputBar = [nibs objectAtIndex:2];
//            }
            else if (barStyle == HOTCharBarStyleForReplayWithEmjo) {
                
                //带表情的
                self.chatInputBar = [nibs firstObject];
            }
            
            
        }
        self.chatInputBar.topVc = self;
        //UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
        
        self.chatInputBar.frame = CGRectMake(0, self.view.bounds.size.height - self.chatInputBar.bounds.size.height, self.chatInputBar.bounds.size.width, self.chatInputBar.bounds.size.height);
        
        [self.view addSubview:self.chatInputBar];
        
        //self.chatTextView.inputAccessoryView = self.chatTextView;
    }
}

-(void)keyBoardWillChanged:(NSNotification *)notification {
    
    NSDictionary *userInfo = notification.userInfo;
    NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    
    CGRect keyboardRect;
    [value getValue:&keyboardRect];
    
    self.keyBoardFrame = keyboardRect;
    
    if (self.chatInputBar) {
        CGPoint newPoint = [self.view convertPoint:keyboardRect.origin fromView:[[UIApplication sharedApplication] keyWindow]];
 
        float newOrgY = newPoint.y - self.chatInputBar.frame.size.height;
        
        if (newOrgY > self.view.frame.size.height) {
            
            newOrgY = self.view.frame.size.height - self.chatInputBar.frame.size.height;
        }
        
        
        __weak HOTBaseViewController *unretainObj = self;
        [UIView animateWithDuration:0.2 animations:^{
            unretainObj.chatInputBar.frame = CGRectMake(unretainObj.chatInputBar.frame.origin.x, newOrgY, unretainObj.chatInputBar.frame.size.width, unretainObj.chatInputBar.frame.size.height);
        } completion:^(BOOL finished) {
            
            if (finished) {
                [unretainObj chatBarFrameWillChange:CGPointMake(unretainObj.chatInputBar.frame.origin.x, newOrgY)];
            }
        }];
    }
}

-(void)chatBarFrameWillChange:(CGPoint)newPoint {
    
    
}

-(void)afterPopWithViewController:(UIViewController *)vc {
    
    
}

-(RMStore *)storeHandler {
    
    if (_storeHandler == nil) {
        
        _storeHandler = [RMStore defaultStore];
        [_storeHandler clearPurchases];
    }
    return _storeHandler;
}

- (void)dealloc
{
    isAppeared = NO;
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
}

-(HOTConfig *)config {
    
    return [HOTConfig config];
}

-(BOOL)checkErrResult:(NSError *)error errMsg:(NSString *)errMsg  {
    
    if (error) {
        
        //error != nil 的时候为网络问题，不属于业务问题
        NSString *networkdErrMsg = [self parseError:error];
        
        ZZZPopupView *popupView = [[ZZZPopupView alloc] initWithTitle:ALERT_TITLE
                                                              message:networkdErrMsg
                                                             delegate:nil
                                                    cancelButtonTitle:nil
                                                     otherButtonTitle:ALERT_BTN_OK];
        
        //[popupView setOffset:CGPointMake(0, -50)];
        [popupView showInWindow];
        
        return YES;
    }
    
    
    //接口调用成功
    if ([errMsg isEqualToString:@"-110"]/*余额不足的情况*/) {
        
        errMsg = MSG_NOT_ENOUGH; //現が不足しています。
        
        ZZZPopupView *popupView = [[ZZZPopupView alloc] initWithTitle:ALERT_TITLE
                                                              message:errMsg
                                                             delegate:self
                                                    cancelButtonTitle:ALERT_BTN_CANCEL
                                                     otherButtonTitle:ALERT_BTN_GO_TO_SHOP];
        popupView.tag = 99993;
        //[popupView setOffset:CGPointMake(0, -50)];
        [popupView showInWindow];
        return YES;
    }
    
    
    return NO;
}

-(NSString *)parseError:(NSError *)error {
    
    NSString *errMsg = error.domain;
    switch (error.code) {
        case NSURLErrorUnknown:
            errMsg = REQ_ERROR_UNKNOW;
            break;
        case NSURLErrorCancelled:
            errMsg = REQ_ERROR_CANCEL;
            break;
        case NSURLErrorBadURL:
            errMsg = REQ_ERROR_BAD_URL;
            break;
        case NSURLErrorTimedOut:
            errMsg = REQ_ERROR_TIMEOUT;
            break;
        case NSURLErrorUnsupportedURL:
            errMsg = REQ_ERROR_UNSUPPORT;
            break;
        case NSURLErrorCannotFindHost:
            errMsg = REQ_ERROR_CONT_FIND_HOST;
            break;
        case NSURLErrorCannotConnectToHost:
            errMsg = REQ_ERROR_CONT_CONNECT_HOST;
            break;
        case NSURLErrorNetworkConnectionLost:
            errMsg = REQ_ERROR_UNKNOW;
            break;
        case NSURLErrorDNSLookupFailed:
            errMsg = REQ_ERROR_DNS;
            break;
        case NSURLErrorHTTPTooManyRedirects:
            break;
        case NSURLErrorResourceUnavailable:
            errMsg = REQ_ERROR_RESOURCE_UNAVAILABLE;
            break;
        case NSURLErrorNotConnectedToInternet:
            errMsg = REQ_ERROR_CONNECT_INTERNET;
            break;
        case NSURLErrorRedirectToNonExistentLocation:
            break;
        case NSURLErrorBadServerResponse:
            break;
        case NSURLErrorUserCancelledAuthentication:
            break;
        case NSURLErrorUserAuthenticationRequired:
            break;
        case NSURLErrorZeroByteResource:
            break;
        case NSURLErrorCannotDecodeRawData:
            break;
        case NSURLErrorCannotDecodeContentData:
            break;
        case NSURLErrorCannotParseResponse:
            break;
        case NSURLErrorFileDoesNotExist:
            break;
        case NSURLErrorFileIsDirectory:
            break;
        case NSURLErrorNoPermissionsToReadFile:
            break;
        case NSURLErrorDataLengthExceedsMaximum:
            break;
        default:
            errMsg = REQ_ERROR_UNKNOW;
            break;
    }
    
    return errMsg;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
